#include <benchmark/benchmark.h>

#include "utils/dbutils.hpp"
#include "utils/kvutils.hpp"
#include "utils/testutils.hpp"

void DBInit() { DBWrapper::GetInstance()->Init(); }

static void BM_KVIterate(benchmark::State& state) {
  for (auto _ : state) {
    KVWrapper::GetInstance("test")->Iterate();
  }
}

static void BM_KVGet(benchmark::State& state) {
  for (auto _ : state) {
    KVWrapper::GetInstance("test")->Get(RandomString(10));
  }
}

static void BM_KVPut(benchmark::State& state) {
  for (auto _ : state) {
    KVWrapper::GetInstance("test")->Put(RandomString(10), RandomString(10));
  }
}

static void BM_DBIterate(benchmark::State& state) {
  for (auto _ : state) {
    DBWrapper::GetInstance()->Iterate("test");
  }
}

static void BM_DBInsert(benchmark::State& state) {
  for (auto _ : state) {
    DBWrapper::GetInstance()->Insert("test",
                                     {RandomString(10), RandomString(10));
  }
  }

  static void BM_DBSelect(benchmark::State & state) {
    for (auto _ : state) {
      auto sql = "select * from test where key = " + RandomString(10) + ";";
      DBWrapper::GetInstance()->Select(sql);
    }
  }

  BENCHMARK(BM_KVIterate);
  BENCHMARK(BM_KVGet);
  BENCHMARK(BM_KVPut);
  BENCHMARK(BM_DBIterate);
  BENCHMARK(BM_DBInsert);
  BENCHMARK(BM_DBSelect);

  BENCHMARK_MAIN();